//
//  CKSettingViewController.m
//  ckjntiku
//
//  Created by Eileen Vivian on 2017/11/23.
//  Copyright © 2017年 Eileen Vivian. All rights reserved.
//

#import "CKSettingViewController.h"
#import "CKLoginViewController.h"
#import "SZKCleanCache.h"
#import "CKCacheViewController.h"
#import "CKIdeaReplyViewController.h"
#import "CKAboutUsViewController.h"

@interface CKSettingViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *setTableView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableviewHeight;
@property (strong, nonatomic) NSArray *myArray;
@end

@implementation CKSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"其他设置";
    _setTableView.scrollEnabled = NO;
    //设置圆角
    [_exitBtn.layer setCornerRadius:25];
    _exitBtn.layer.masksToBounds = YES;
  
    self.myArray=@[@"清理缓存",@"反馈咨询",@"电话咨询",@"公司风采",@"关于我们"];
        _setTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
- (IBAction)extClick:(UIButton *)sender {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"确定要退出登录吗?" message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    UIAlertAction*okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        CKLoginViewController  * zmLoginVC = [[CKLoginViewController alloc]init];
        [self presentViewController:zmLoginVC animated:YES completion:nil];
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.myArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ID"];
    }
    cell.textLabel.text = self.myArray[indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        //清楚缓存
        [SZKCleanCache cleanCache:^{
        }];
        UILabel *downloadLabel = [[UILabel alloc]init];
        //设置控件居中u
        downloadLabel.center = self.view.superview.center;  //让标签的中心和屏幕的中心重合
        downloadLabel.bounds = CGRectMake(0, 0, 200, 40);  //设置标签的大小
        downloadLabel.backgroundColor = [UIColor blackColor];
        downloadLabel.text = [NSString stringWithFormat:@"清理内存成功"];
        downloadLabel.textColor = [UIColor redColor];
        downloadLabel.textAlignment = NSTextAlignmentCenter;
        //设置Label的圆角半径
        downloadLabel.layer.cornerRadius = 15;
        downloadLabel.layer.masksToBounds = YES;
        //设置标签的透明度
        downloadLabel.alpha = 0;
        //开启一段block动画
        [UIView animateWithDuration:0.5 animations:^{
            //使用2秒钟的时间开启一段动画,将透明度设置为0.7,即可见
            downloadLabel.alpha = 0.7;
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.5 animations:^{
                downloadLabel.alpha = 0;
            }completion:^(BOOL finished) {
            }];
        }];
        [self.view.superview addSubview:downloadLabel];
    }else if (indexPath.row == 1){
        CKIdeaReplyViewController * ckIdeaReplyVC = [[CKIdeaReplyViewController alloc]init];
        [self.navigationController pushViewController:ckIdeaReplyVC animated:YES];
    }else if (indexPath.row == 2){
       [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"tel://400-096-0601"]];
    }else if(indexPath.row == 3){
         CKCacheViewController * ckCacheVC = [[CKCacheViewController alloc]init];
         [self.navigationController pushViewController:ckCacheVC animated:YES];
    }else if(indexPath.row == 4){
        CKAboutUsViewController * ckAboutVC = [[CKAboutUsViewController alloc]init];
        [self.navigationController pushViewController:ckAboutVC animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
